home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / rdsh_11.zoo / desktop.zoo / iq_boot.zoo / iq_boot.c next >
C/C++ Source or Header  |  1992-04-30  |  7KB  |  226 lines

  1. /*        IQ_BOOT.PRG    ( The Intelligent Boot_Program )     */
  2. /*    Embryo sourcecode for an intelligent boot program meant to boot
  3.     your system off a "booting" RDY\RDE ramdisk ( P:\ is best choice )
  4.     "Tailor" it to your needs - No "Package" boot program is as flexible
  5.  
  6.     compile in MWC with:      cc  -V -VSMALL -Nrcrtsg.o -s iq_boot.c
  7.     or use the supplied   makefile
  8.  
  9.                     W. Alan B. Evans  [wabe@ukc.ac.uk]
  10. */
  11.  
  12. #include <osbind.h>
  13.  
  14.  
  15. /*  Cheap & minimal gets alternative - Saves a little space over gets() */
  16. /*    But on earlier TOSes    CONTROL-C  is not recognised    */
  17.  
  18. char *gts(data)
  19. char *data;
  20. {    register char *p = data;
  21.     while ((*p=gemdos(1)) != '\r')
  22.     if (*p == '\010') { --p; Cconws(" \010"); } else p++;
  23.     *p= '\0';
  24.     if (*data)    return(data);    else    return((char *)0);
  25. }
  26.  
  27. /*   Filecopying Subroutine - Preserves DateStamp - very useful generally */
  28.  
  29. int fc(file1,file2)
  30. char *file1,*file2;
  31.  
  32. {    register char *buf;
  33.     int i,handle1,handle2,nsects,nsecmax,erc,no_tms,info[2];
  34.     long lo,nrw,flngth;
  35.  
  36.     erc= 0;    buf= 0;
  37.     if ((nsecmax = (int)(Malloc(-1L)/0x200L)-4) < 0)
  38.     { gemdos(9,"\r\n  INSUFFICIENT MEMORY!! ");  goto end;    }
  39.  
  40.     if ((handle1 = Fopen(file1,0)) < 0) return(0);
  41.     Fdatime(info,handle1,0);
  42.     flngth= Fseek(0L,handle1,2);
  43.     nsects= 1+(int)(flngth/0x200L);
  44.     if ((no_tms= nsects/nsecmax) == 0) nsecmax= nsects;
  45.  
  46.     if ((handle2 = Fopen(file2,0)) > 0)
  47.     { Fclose(handle2); Fdelete(file2);    }
  48.     if ((handle2 = Fcreate(file2,0)) < 0 )
  49.     { gemdos(9,"\r\n Fcreate FAILURE - COULD NOT OPEN FILE: ");
  50.     gemdos(9,file2);    --erc; goto end; }
  51.  
  52.     if ((buf= (char *)Malloc((long)nsecmax*0x200L+0x200L)) == 0)
  53.     { gemdos(9,"\r\n Malloc FAILURE!!! "); --erc; goto end; }
  54.     Cconws("\r\n  Copying "); Cconws(file1);
  55.     Cconws(" to "); Cconws(file2); Cconws("\r\n");
  56.     i=-1; while (i++ < no_tms)
  57.     { if (i == no_tms) nrw= flngth- (long)nsecmax*0x200L*i;
  58.     else  nrw= (long)nsecmax*0x200;
  59.  
  60.     { if ((lo= Fseek((long)nsecmax*0x200L*i,handle1,0) < 0) 
  61.     || (lo=Fread(handle1,nrw,buf)) != nrw)
  62.     { gemdos(9,"\r\n Fseek or Fread FAILURE");  --erc; goto end;    }
  63.     }
  64.  
  65.     { if ((lo= Fseek((long)(nsecmax*0x200L*i),handle2,0) < 0) 
  66.     || (lo= Fwrite(handle2,nrw,buf)) != nrw)
  67.     { gemdos(9,"\r\n Fseek or Fwrite FAILURE!  DISK FULL? "); --erc; goto end; }
  68.     }
  69.     }    /*  end of i loop  */
  70.  
  71. end:    if (!Fclose(handle2))
  72.     { if (erc < 0) Fdelete(file2); else
  73.     { handle2=Fopen(file2,0); Fdatime(info,handle2,1); Fclose(handle2); }
  74.     }
  75.     if (buf != 0) Mfree(buf);
  76. return(erc);
  77. }
  78.  
  79.  
  80.  
  81. main()
  82.  
  83. {    int sv,i,dev;    long drv,st;    char ch,c,file[100],num[100];
  84.     char *gts(),strcpy(),*strcat();
  85.  
  86. /* Check for Character Code input at Boot Time and, if present, capitalize it */
  87.     if (Cconis()== -1)    ch= (Crawcin() & 0x5f);
  88.  
  89. /*  Load the Hard_disk Program if 'H' has not been Keyed    */
  90.     if (ch != 'H') Pexec(0,"AUTO\\AHDI\0","\0","\0");
  91.  
  92. /* Life_Saver Feature: Enter Shell to cure corrupted Boot Programs, ACC's etc.*/
  93.     if (ch == 'X') {    Cconws("\r\n\n  PROGRAM PATH\\NAME= ");
  94.     Pexec(0,gts(file),"\0","\0");
  95.     }
  96.  
  97. /*  Check if Utility Ram Disk O:\ is Present, and if not, offer to load it */
  98.     if (!((drv=Drvmap()) & 040000))    {
  99.     Cconws("\r\n  Load UTIL_O Ramdisk? [y] ");
  100.     st=0L;
  101. /*  Wait for about 10 seconds for key_input    */
  102.     while (!Cconis() && ++st < 25000L)  ;
  103. /*  If no key-input after 10 secs, do the default load    */
  104.     if (!Cconis() || (Cconin() & 0x5f) != 'N')
  105.     if (Pexec(0,"C:\\UTIL_O.PRG\0","\0","\0"))
  106.     { Cconws("\r\n  Insert UTIL_O Floppy & Hit key ");
  107.     Crawcin(); Pexec(0,"A:\\UTIL_O.PRG\0","\0","\0");    }
  108.     }
  109. /*  If O:\ Loads successfully a warm start ensues and booting restarts */
  110.  
  111. /*  Check for TOS Versions requiring the POOLFIX patch and implement it */
  112.     if ((sv=Sversion()) >= 0x1400      /*  NEW TOS Present!    */
  113.     && sv <= 0x1500 && Pexec(0,"O:\\POOLFIX?.PRG\0","\0","\0") &&
  114.     Pexec(0,"C:\\POOLFIX?.PRG\0","\0","\0"))
  115.     Pexec(0,"A:\\POOLFIX?.PRG\0","\0","\0");
  116.  
  117. eto:    i=0;    for (dev=0;dev<=15;++dev) {
  118.     if (drv & 1L<<dev) {file[i++]= 'A'+dev; file[i+1]='\0'; }
  119.     }
  120.     Cconws("\r\n\n    VOLUMES PRESENT = \033p");    Cconws(file);
  121.     strcpy(file," \0");
  122.     Cconws("\033q\r\n\n\
  123.     \033K\033p Optionally use RDSH to LOAD|DROP|COPY Ramdisks/Files etc.\033q\r\n\
  124.   Enter RDSH Command: \033e");
  125.     if  (gts(num))    {    strcat(file,num);
  126.  
  127. /*   Try to Find RDSH on O:\, then on C:\ and lastly on A:\    */
  128.     if (Pexec(0,"O:\\RDSH.PRG\0",file,"\0")== -33  &&
  129.     Pexec(0,"C:\\RDSH.PRG\0",file,"\0") == -33  &&
  130.     Pexec(0,"A:\\RDSH.PRG\0",file,"\0"))    goto eto;
  131.     }
  132.  
  133.     Cconws("\r\n\n\
  134.       CHOOSE DESKTOP [def = Previous Desktop]\r\n\n\
  135.     Signum2           s    Timeworks     t\r\n\
  136.     Mark Williams C v_3      m    Fortran_2.154     j\r\n\
  137.     Degas Elite          d    WordPlus     w\r\n\
  138.     Fontmake           f    General Purpose     g\r\n\
  139.     Other:  Enter PATH to DESKTOP.INF (e.g. C:, E:\\MAIL etc. )\r\n\
  140.     \033e");
  141.  
  142.     Cconws("\033f");
  143.     if (gts(file))    {
  144.     if (strlen(file) < 2)    {
  145.  
  146.     if ((c= (file[0] & 0x5f)) == 'S')    {
  147.     if (drv & 0400) strcpy(file,"I:\0");
  148.     else    {    strcpy(file,"D:\\SIGNUM\0");
  149. /*  Load Signum Resident Code    */
  150.     if (Pexec(0,"D:\\SIGNUM\\INSTAL.PRG\0","\0","\0"))
  151.     Cconws("\r\n  WARNING: INSTAL NOT LOADED! ");    }
  152.     }
  153.  
  154.     if (c == 'M') if (drv & 0200) strcpy(file,"H:\0");
  155.     else strcpy(file,"C:\\MWC30\0");
  156.  
  157.     if (c == 'J') strcpy(file,"J:\0");
  158.  
  159.     if (c == 'W')     strcpy(file,"C:\\WORDPLUS\0");
  160.  
  161.     if (c == 'T')    {    strcpy(file,"E:\\PUBLISH\0");
  162. /*  Load GDOS for Timeworks        */
  163.     fc("E:\\PUBLISH\\ASSIGN.SYS\0","ASSIGN.SYS\0");
  164.     Pexec(0,"E:\\PUBLISH\\GDOS.PRG\0","\0","\0");
  165.     }
  166.  
  167.     if (c == 'D') strcpy(file,"D:\\DEGAS\0");
  168.  
  169. /*  Load General Purpose Desktop, kept in AUTO folder of Ramdisk    */
  170.     if (c == 'G') strcpy(file,"AUTO\0");
  171.     }
  172.  
  173. /*   Add filename to the selected Path to Desktop    */
  174.     strcat(file,"\\DESKTOP.INF\0");
  175.     }
  176.  
  177. /*   Optionally Load GDOS    */
  178.     if (c != 'T')    {
  179.     Cconws("\r\n  Load GDOS? [n] ");
  180.     if ((Cconin() & 0x5f) == 'Y')    {
  181.     fc("E:\\PUBLISH\\ASSIGN.SYS\0","ASSIGN.SYS\0");
  182.     Pexec(0,"E:\\PUBLISH\\GDOS.PRG\0","\0","\0");
  183.     }}
  184.  
  185. /*  Check for presence of drive C:\ and accordingly depending on TOS Version */
  186.     if (drv & 04)    /*  C:\ Disk Present    */
  187.     { if (sv >= 0x1400) { if (*file) fc(file,"C:\\DESKTOP.INF\0"); }
  188.  
  189. /*  Increase 40-Folder Limit on old TOSes if C:\ is present    */
  190. /*   NOTE: IQ_BOOT.PRG in "booting" AUTO-folder is renamed to FOLDRXXX.PRG
  191.      where  XXX  is the desired number of extra folders e.g. FOLDR200.PRG   */
  192.     else  Pexec(0,"C:\\FOLDR???.PRG\0","\0","\0");
  193.     }
  194.  /*  If C:\ absent, ACC's load from the booting Ramdisk - so copy them in */
  195.     else  fc("A:\\CONTROL.ACC\0","CONTROL.ACC\0");
  196.  
  197. /*  On older TOSes the DESKTOP.INF must be on the booting RAM_DISK Rootdir */
  198.     if (*file && sv < 0x1400)    fc(file,"DESKTOP.INF\0");
  199.  
  200. /*  Some default tasks ( Tailor these to your own needs )    */
  201. /*  Set ICD Clock on Hard Disk    */
  202.     Pexec(0,"C:\\BIN\\TIMESET.PRG\0","\0","\0");
  203.  
  204. /*  Load ANTIBOMB Utility    */
  205.     if (Pexec(0,"O:\\ANTIBOMB.PRG\0","\0","\0") == 33)
  206.     Pexec(0,"C:\\ANTIBOMB.PRG\0","\0","\0");
  207.  
  208. /*  If Signum2 loaded on Ramdisk I:\, load its Libraries    */
  209.     Pexec(0,"I:\\INSTAL.PRG\0","\0","\0");
  210.  
  211. /*  For Older TOSes load the COPYFIX Program to preserve DATE/TIME stamp */
  212.     if ( sv < 0x1400 && Pexec(0,"O:\\COPYFIX.PRG\0","\0","\0")
  213.     && Pexec(0,"C:\\COPYFIX.PRG\0","\0","\0"))
  214.     Pexec(0,"A:\\COPYFIX.PRG\0","\0","\0");
  215.  
  216. /*   etc.  etc.        */
  217.  
  218. /*  Lastly, if you wish to load MINT, do so here    */
  219.     Cconws("\r\n  Load MINT? [n] ");
  220.     if ((Cconin() & 0x5f) == 'Y') Pexec(0,"C:\\MINT.PRG\0","\0","\0");
  221.  
  222. Pterm0();
  223. }
  224.  
  225.  
  226.